using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Localization;
using SinBiota.Model.Entities.CustomAttributes;

namespace SinBiota.Model.Entities
{
    [LocalizedName("TaxonomicGroup", NameResourceType = typeof(Strings))]
    public class LegacyTaxonomicGroup : BaseEntity
    {
        [LocalizedName("Name", NameResourceType = typeof(Strings))]
        [Required(ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "FieldCannotBeEmpty")]
        public virtual String Name { get; set; }

        [LocalizedName("LegacyTaxonomicClassification", NameResourceType = typeof(Strings))]
        public virtual String LegacyTaxonomicClassification { get; set; }

        public virtual string RequiredRanks { get; set; }

        public virtual IDictionary<string, string> LegacyTaxonomyToDictionary()
        {
            return LegacyTaxonomicClassification.Split(';').Select(pair => pair.Split('@')).ToDictionary(x => x[0], x => x[1]);
        }

        public virtual IDictionary<string, string> LegacyTaxonomyLocalizedToDictionary()
        {
            return LegacyTaxonomicClassification.Split(';').Select(pair => pair.Split('@')).ToDictionary(x => Taxonomy.ResourceManager.GetString(x[0]), x => x[1]);
        }

        public virtual IList<string> RequiredRanksList()
        {
            return RequiredRanks.Split(';');
        }

        public virtual IList<string> RequiredRanksListWithoutDepositaryTerms()
        {
            return RequiredRanks.Split(';').Where(t => t != "ui" & t != "ud" & t != "autor_ano").ToList();
        }
        public virtual IList<string> RequiredRanksListWithoutDepositaryTermsLocalized()
        {
            return RequiredRanksListWithoutDepositaryTerms().Select(x => Taxonomy.ResourceManager.GetString(x)).ToList();
        }
        public virtual object LegacyTaxonomyLocalizedToListPairs()
        {
            return LegacyTaxonomicClassification.Split(';').Select(pair => pair.Split('@')).Select(x => new { rank = Taxonomy.ResourceManager.GetString(x[0]), name = x[1] }).ToList();
        }
    }
}